<template>
  <div v-if="routeName === 'Realestate'" class="list-page">
    <div class="block-wrap filter-form">
      <el-form :inline="true" :model="form" size="small" label-width="140px">
        <!-- <el-form-item>
          <el-select
            slot="label"
            v-model="form.type"
            style="width: 120px"
            placeholder="所属区域"
          >
            <el-option value="1">长沙</el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="项目名称:">
          <el-input placeholder="请输入" v-model="form.xmmc" />
        </el-form-item>
        <el-form-item label="幢编号:">
          <el-input placeholder="请输入" v-model="form.zbm" />
        </el-form-item>
        <el-form-item label="坐落:">
          <el-input placeholder="请输入" v-model="form.zl" />
        </el-form-item>
        <el-form-item class="filter-form-btns">
          <el-button type="primary" @click="search">查询</el-button>
          <!-- <el-button type="default">重置</el-button> -->
        </el-form-item>
      </el-form>
    </div>
    <div class="block-wrap">
      <el-table
        :data="dataList"
        style="width: 100%;"
        align="center"
        header-align="center"
        :header-cell-style="headerStyle"
        :cell-style="cellStyle"
        v-loading="loading"
      >
        <el-table-column
          type="index"
          label="序号"
          width="60"
          :index="getIndex"
        />
        <el-table-column prop="xmmc" label="项目名称" />
        <el-table-column prop="zbm" label="幢编码" />
        <el-table-column prop="dh" label="栋号" />
        <el-table-column prop="jzjg" label="建筑结构">
          <template slot-scope="scope">
            {{ getBstruct(scope.row.jzjg) }}
          </template>
        </el-table-column>
        <el-table-column prop="jzyt" label="建筑用途">
          <template slot-scope="scope">
            {{ getPurpose(scope.row.jzjg) }}
          </template>
        </el-table-column>
        <el-table-column prop="zl" label="坐落" />
        <el-table-column prop="options" label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="handleDetail(scope.row)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
    <div class="footer">
      Copyright © 2018-2020 湖南智慧政务区块链科技有限公司
    </div>
  </div>
  <router-view v-else :key="key" />
</template>

<script>
import { getPropertiesInfoList } from "@/api/propertiesInfo";
export default {
  name: "Realestate",
  data() {
    return {
      form: {
        xmmc: "",
        zbm: "",
        zl: "",
        page: 1,
        pageSize: 10
      },
      dataList: [],
      total: 0,
      currentPage: 1,
      loading: false
    };
  },
  computed: {
    key() {
      return this.$route.path;
    },
    routeName() {
      return this.$route.name;
    }
  },
  created() {
    this.getPropertiesInfoList();
  },
  methods: {
    getPropertiesInfoList() {
      this.loading = true;
      getPropertiesInfoList(this.form)
        .then(res => {
          this.dataList = res.data.budingInfoResp;
          this.total = res.data.pageResp.sizeCount;
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    search() {
      this.getPropertiesInfoList();
    },
    handleSizeChange() {
      this.form.size = val;
      this.getForecastList();
    },
    handleCurrentChange() {
      this.form.page = val;
      this.getForecastList();
    },
    getBstruct(row) {
      switch (row) {
        case "1":
          return "钢结构";
        case "2":
          return "钢和钢筋混凝土结构";
        case "3":
          return "钢筋混凝土结构";
        case "4":
          return "混合结构";
        case "5":
          return "砖木结构";
        case "6":
          return "其它结构";
      }
    },
    getPurpose(row) {
      switch (row) {
        case "1":
          return "钢结构";
        case "2":
          return "钢和钢筋混凝土结构";
        case "3":
          return "钢筋混凝土结构";
        case "4":
          return "混合结构";
        case "5":
          return "砖木结构";
        case "6":
          return "其它结构";
      }
    },
    handleDetail(row) {
      this.$router.push({
        name: "RealestateDetail",
        query: { housenum: row.zbm }
      });
    },
    headerStyle() {
      return {
        background: "#F5F9FF",
        color: "#2E2E30"
      };
    },
    cellStyle() {
      return {
        height: "48px",
        padding: "0"
      };
    },
    getIndex($index) {
      return $index + (this.form.page - 1) * this.form.pageSize + 1;
    }
  }
};
</script>

<style lang="scss">
@import "~@/styles/page/list-page.scss";
.block-wrap {
  padding: 25px;
  background: #fff;
  border-radius: 2px;
  margin-bottom: 16px;
}
.el-table .el-table__cell {
  text-align: center;
}
.el-button--text {
  min-width: 30px;
}
.footer {
  text-align: center;
  margin-top: 50px;
  font-size: 12px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.45);
  line-height: 20px;
}
.el-pagination .btn-prev,
.el-pagination .btn-next,
.el-pagination .el-pager li {
  border: 1px solid #eee;
  margin-right: 8px;
}
.el-pager li.active + li {
  border-left: 1px solid #eee;
}
.el-pager li.active {
  border-color: #295ec8;
}
</style>
